<?php
/**
 * Read datasource config file'
 * <code>
 * <?php
 * $reader = new ConfigReader();
 * $result = $reader->readConfigFromFile($dbConfFile);
 * $db = new Database( $result[0]->datasources[0] );
 * ?>
 * </code>
 * @author Artur Kmera <artur.kmera@3code.pl>
 * @version 0.9
 * @package ORM
 * @subpackage Schema
 * @link http://arrowplatform.org/orm
 * @copyright 2011 Arrowplatform 
 * @license GNU LGPL
*/
class ConfigReader{
	
	/**
	 * Parse config file
	 * @param string $file
	 * @return Group []
	 * @todo Create Config object witch will be cacheable and implements metchots like "getActiveGroup()"
	 */
	public function readConfigFromFile($file){
		
		$sxml = simplexml_load_file($file);
		
		$xmlGroups = $sxml->xpath('/datasources/group');
		$groups  = array();
		foreach($xmlGroups as $xmlGroup){
			$group = new Group();
			$group->active = (isset($xmlGroup["active"]) && "".$xmlGroup["active"] == 1)?true:false;
			$groups[] = $group;
			$group->datasources = array(); 
			foreach($xmlGroup->datasource as $xmlDatasource){
				
				$datasource = new Datasource();
				$datasource->connectionString = (String) $xmlDatasource->connectionString;
				$datasource->charset = (String) $xmlDatasource->charset;
				$datasource->transactions = ("".$xmlDatasource->charset == "1" )?true:false;
				$group->datasources[] = $datasource;
			}
		}
		
	    
		return $groups;
	}
	
}
?>